function Delta=Delta_fun(rho,default)
%--------------------------------------------------
% this function calculates the gain from choosing X^*= rho rather than the
% default d
% it sets Delta equal to missing (NaN) in case there is no default (=0)

n=length(rho);


Delta=((rho.^2)+(default.^2))./2 - rho.*default;

for i=1:n;
    if default(i,1)==0;
        Delta(i,1)=NaN;
    end


end 